<template>
  <view class="box bd1 t1">
    <view style="text-align: center; font-size: 36upx; margin: 0 0 30upx"
      >预约提醒</view
    >
    <view class="time-line flex flex-j-b">
      <view>
        <view>预约者姓名:{{ config.globalData.user.userName }}</view>
        <view
          >预约时间：{{ appointmentInfo.subscribeTime }}({{
            appointmentInfo.timeSolt
          }})</view
        >
        <view>当前所在社区：{{ sq }}</view>
        <view v-if="appointmentInfo.planType != 4"
          >预约内容：{{ appointmentInfo.planType | planTypeFilter
          }}{{ deptName }}</view
        >
        <view v-if="appointmentInfo.planType == 4">预约内容：{{ yyname }}</view>
        <view>预约号码：{{ appointmentInfo.subscribeCode }}</view>
        <view v-if="showstate == 0">当前状态：您已过号，请重新取号</view>
        <view v-else-if="showstate == 1"
          >当前人数：当前排队有{{ allnum }}人,您排在第{{ usernum }}位</view
        >
        <view v-else>当前状态：等待接种</view>
      </view>
      <!-- <u-button type="primary" size="mini" style="margin: 0;">更改</u-button> -->
    </view>
    <!-- <view class="closeBtn flex flex-al-c" @tap="openCard">
			{{isCloseLetter?'收起':'更多'}}
			<view class="iconfont" :class="{'iconarrow-down-s-fill': !isCloseLetter,'iconarrowup':isCloseLetter}">
			</view>
		</view> -->
    <view class="more" :style="{ height: isCloseLetter ? '250upx' : '0' }">
      <view style="font-weight: bold">
        备注：如您已到现场请点击下方“现场签到”按钮，获取优先位置</view
      >
      <!-- 点击过号补签，提示该功能为会员服务，是否需要开通会员 -->
      <view class="flex flex-j-b" style="margin-top: 30rpx">
        <u-button
          type="primary"
          size="mini"
          style="margin: 0; color: #d9d9d9; font-size: 26rpx"
          shape="circle"
          @click="qdao"
          :disabled="appointmentInfo.isAbsence != 0"
          >{{
            appointmentInfo.isAbsence == 0 ? "现场签到" : "已签到"
          }}</u-button
        >
        <!-- 	<u-button type="primary" size="mini" style="margin: 0;" shape="circle"
					:disabled="appointmentInfo.overNumberBq!=0" @click="tc">
					{{appointmentInfo.overNumberBq==1?'已签到':'过号补签'}}</u-button> -->
        <u-button
          type="primary"
          size="mini"
          style="margin: 0; font-size: 26rpx"
          shape="circle"
          @click="getPeople"
        >
          {{ !isget ? "刷新队列" : "刷新中.." }}</u-button
        >
        <u-button
          type="primary"
          size="mini"
          style="margin: 0; font-size: 26rpx"
          shape="circle"
          @click="quit"
          :disabled="aaa"
        >
          取消预约</u-button
        >
      </view>
    </view>
  </view>
</template>
<script>
import Qs from "qs";
export default {
  data() {
    return {
      isCloseLetter: true,
      community: {},
      appointmentInfo: {},
      aaa: false,
      sq: "", //社区
      atName: "", //当前名字
      atPhone: "", //当前号码
      yyname: "", //存放孕妇预约内容
      allnum: "", //所有人数
      usernum: "", //当前人数
      showstate: "", //队列状态
      isget: false,
    };
  },
  props: {
    message: Object,
  },
  props: ["planType", "message", "deptId", "deptName"],
  filters: {
    planTypeFilter(inp) {
      // 儿童接种、儿童保健、儿童门诊、孕妇产检、孕妇接种、孕妇门诊、老年人体检、
      // 老年人接种、老年人门诊、普通人接种、普通人门诊
      let str = "";
      if (inp == "1") str = "儿童接种";
      if (inp == "2") str = "儿童保健";
      if (inp == "3") str = "儿童门诊";
      if (inp == "4") str = "孕妇产检";
      if (inp == "5") str = "孕妇接种";
      if (inp == "6") str = "孕妇门诊";
      if (inp == "7") str = "老年人体检";
      if (inp == "8") str = "老年人接种";
      if (inp == "9") str = "老年人门诊";
      if (inp == "10") str = "普通人接种";
      if (inp == "11") str = "普通人门诊";
      if (inp == "12") str = "门诊预约";
      return str;
    },
  },
  onLoad() {
    this.config.getLoginInfo();
  },
  updated() {
    // this.shequ()
    let a = this.$store.state.yyname || uni.getStorageSync("yfname");
    this.yyname = a;
  },
  methods: {
    father() {
      this.$emit("fds");
    },
    shequ(communityId) {
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config
        .post("/communityInfo/getCommunityDetail", {
          deptId: communityId,
        })
        .then((res) => {
          console.log(res);
          uni.hideLoading();
          if (res.data.code === 200) {
            this.sq = res.data.data.deptName;
            this.atPhone = res.data.data.mobile;
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    openCard() {
      this.isCloseLetter = !this.isCloseLetter;
    },
    // 获取预约信息
    getAppInfo() {
      let self = this;
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config
        .get("/subscribesInfos/getSubscribesInfo", {
          type: this.planType || "",
          deptId: this.community.deptId,
          deptIds: this.deptId || "",
        })
        .then((res) => {
          uni.hideLoading();
          console.log(res.data.data.communityId);
          this.shequ(res.data.data.communityId); //获取社区
          if (res.data.code === 200) {
            self.appointmentInfo = res.data.data;
            this.getPeople();
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    oldqdao() {
      // uni.showToast({
      // 	title: '该功能暂未开通',
      // 	icon: 'none'
      // });
      let atTime = this.appointmentInfo.timeSolt;
      //console.log(atTime)
      let self = this;
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config
        .get("/subscribesInfos/updateQd", {
          planType: this.appointmentInfo.planType,
        })
        .then((res) => {
          uni.hideLoading();
          if (res.data.code === 200) {
            this.getAppInfo();
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    qdao() {
      let data = {
        userId: this.config.globalData.user.id,
        planType: this.appointmentInfo.planType || "",
        deptId: this.config.globalData.user.deptId,
        deptIds: this.deptId || "",
      };
      const innerURL = this.config.finIp(); //预约内部地址

      uni.request({
        //http://39.98.118.19:8080  ios 8090
        url: innerURL + "/subscribesInfos/updateQd", //仅为示例，并非真实接
        data: Qs.stringify(data),
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        success: (res) => {
          if (res.data.code === 200) {
            this.getAppInfo();
          } else {
            console.log(res.data.msg);
            uni.showToast({
              title: res.data.msg,
              icon: "none",
            });
          }
        },
      });
    },
    tc() {
      this.config
        .get("/subscribesInfos/getQhBq", {
          id: this.appointmentInfo.id,
        })
        .then((res) => {
          if (res.data.data == 1) {
            this.vipcors();
          } else {
            uni.showToast({
              title: "您不是会员",
              icon: "none",
            });
          }
        });
    },
    //获取当前人数
    getPeople() {
      this.isget = true;
      this.config
        .get("/callNumber/getCallNumber", {
          planType: this.appointmentInfo.planType || "",
          deptId: this.deptId || "",
        })
        .then((res) => {
          setTimeout((s) => {
            this.isget = false;
          }, 1000);
          this.showstate = res.data.data.state;
          this.allnum = res.data.data.allNum;
          this.usernum = res.data.data.userNum;
        });
    },
    //会员过号补签
    vipcors() {
      this.config
        .get("/subscribesInfos/updateQdGh", {
          planType: this.appointmentInfo.planType,
        })
        .then((res) => {
          //console.log(res)
        });
    },
    oldquit() {
      let self = this;
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config
        .get("/subscribesInfos/qxSubscribe", {
          planType: this.appointmentInfo.planType,
          userId: this.config.globalData.user.id,
          deptId: this.config.globalData.user.deptId,
        })
        .then((res) => {
          uni.hideLoading();
          //console.log(res)
          if (res.data.code === 200) {
            this.$parent.getPlanss();
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    quit() {
      //新的 取消预约
      let data = {
        planType: this.appointmentInfo.planType || "",
        userId: this.config.globalData.user.id,
        deptId: this.config.globalData.user.deptId,
        deptIds: this.deptId || "",
      };
      uni.removeStorage({
        key: "yfname",
      });
      //47.94.154.233:8090
      //http://39.98.118.19:8080
      const innerURL = this.config.finIp(); //预约内部地址
      uni.request({
        url: innerURL + "/subscribesInfos/qxSubscribe", //仅为示例，并非真实接
        data: Qs.stringify(data),
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        success: (res) => {
          if (res.data.code === 200) {
            this.$parent.getPlanss();
          } else {
            uni.showToast({
              title: self.config.handleError(res.data),
              icon: "none",
            });
          }
        },
      });
    },
  },
  mounted() {
    this.community = uni.getStorageSync("community")
      ? JSON.parse(uni.getStorageSync("community"))
      : {};
    this.getAppInfo();
    // this.shequ(); //获取社区
  },
};
</script>

<style lang="less" scoped>
.box {
  padding: 30upx 30upx 0;
  background-color: #b0e4fb;
  color: #333;
}

.time-line {
  line-height: 50upx;
  font-size: 32upx;
}

.closeBtn {
  justify-content: flex-end;
  margin: 50rpx 0 0 0;
}

.more {
  margin: 20upx 40upx;
  overflow: hidden;
}
@-webkit-keyframes changeleft {
  0% {
    -webkit-transform: rotate(0deg);
  }

  50% {
    -webkit-transform: rotate(180deg);
  }

  100% {
    -webkit-transform: rotate(360deg);
  }
}
.new {
  -webkit-animation: changeleft 2s linear infinite;
}
</style>
<style scoped>
@media (prefers-color-scheme: closedark) {
  .bd {
    background-color: #1b1c1e !important;
  }
  .bd1 {
    background-color: #38383c !important;
  }
  .t1 {
    color: #ccc !important;
  }
}
</style>
